package com.zuoye.method;

import java.util.Scanner;

import com.zuoye.entity.Student;
import com.zuoye.extend.Common;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/12  16:55
 * @Copyright
 */
public class MethodDome01 extends Common {
    public static Student[] students = new Student[100];
    public static int index =0;
    //登录
    public static int getLogin(Scanner scanner) {
        System.out.println("请输入选项：1.登录2.退出");
        int login = scanner.nextInt();
        return login;
    }

    //增加方法
    public static void add( Scanner scanner) {
        Student student =new Student();
        //一维数组
//        String[] srr = new String[3];
        //名字加入数组
        System.out.println("请输入要添加的名字：");
        String name = scanner.next();
        student.setName(name);

        //性别加入数组
        System.out.println("请输入要添加人的性别： ");
        String sex = scanner.next();
        student.setSex(sex);

        //年龄加入数组
        System.out.println("请输入要添加人的年龄： ");
        int age = scanner.nextInt();
        student.setAge(age);
        students[index] = student;
        index++;
        System.out.println("添加完成！请继续操作：");
//        for (int i = 0; i < students.length; i++) {
//            if(students[i]!=null){
//                System.out.println(students[i].getName()+" , "+students[i].getSex()+" , "+students[i].getAge());
//            }
//        }
    }


    //删除方法
    public static void Del(Scanner scanner, Student[] students) {
        System.out.println("请输入要删除人的姓名：");
        String names = scanner.next();

        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && students[i].getName().equals(names)) {
                students[i]=null;
                break;
            }

        }
        System.out.println("删除完成！请继续操作：");

    }

    //改
    public static void update(Scanner scanner, Student[] students) {
        System.out.println("请输入要修改的用户的姓名");
        String name = scanner.next();

        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && students[i].getName().equals(name)) {
                System.out.println("请输入修改后的用户的姓名：");
               String na = scanner.next();
              students[i].setName(na);
                System.out.println("请输入修改后的用户的性别：");
                String se = scanner.next();
                students[i].setSex(se);
                System.out.println("请输入修改后的用户的年龄：");
                int  ag  = scanner.nextInt();
                students[i].setAge(ag);
                break;
            }
        }
        System.out.println("修改完成！ 请继续操作：");
    }


    //查询方法
    public static void Chaxun(Student[] students) {
        System.out.println("信息如下：");
        for (int i = 0; i < students.length; i++) {
            if(students[i]!=null){
                System.out.println(students[i].getName()+" , "+students[i].getSex()+" , "+students[i].getAge());
            }
        }

        System.out.println("查询完成，请继续操作：");
    }


    //退出
    public static void ext() {
        System.out.println("拜拜！");


    }
}
